/******************************************************/
/* Goblin's Cube - Rubik's cube game for Wii Homebrew */
/* Copyright (C) 2009 Ricardo Bueno Cordeiro          */
/* Licensed under de GNU General Public License v2.0  */
/*   See license_gplv2.txt for detalis                */
/******************************************************/

#ifndef __CONTROL_GAME_H_
#define __CONTROL_GAME_H_

#include <gccore.h>
#include <wiiuse/wpad.h>

#include "control_base.h"

#include "cube.h"

#define HAND_FREE 0
#define HAND_TURN 1
#define HAND_HOLD 2

#define HAND_BUTTON_TURN 0x00000001
#define HAND_BUTTON_HOLD 0x00000002

#define ROTATION_AXIS_TOP_BOTTOM 0
#define ROTATION_AXIS_FRONT_BACK 1
#define ROTATION_AXIS_LEFT_RIGHT 2

#define RIGHT_HANDED 0
#define LEFT_HANDED  1

struct Hand {
	int piece;
	int operation;
	int hold_position;
};

class ControlGame : public ControlBase {
private:
	f32 angle;
	f32 mag;

	int show_instructions;

	int handness;
	Hand left;
	Hand right;

	void get_wiimote_data(WPADData *data, u32 *buttons, struct gforce_t *gforce);
	void get_nunchuk_data(WPADData *data, u32 *buttons, struct gforce_t *gforce);

	void get_left_hand_data(WPADData *data, u32 *buttons, struct gforce_t *gforce);
	void get_right_hand_data(WPADData *data, u32 *buttons, struct gforce_t *gforce);

	int get_left_piece(struct gforce_t *gforce, int current);
	int get_right_piece(struct gforce_t *gforce, int current);

	void get_orientation_mtx(Mtx m);
	void draw_hand(int hand, f32 x, f32 y, f32 z, f32 r, f32 g, f32 b, f32 rotX, f32 rotY);
	void draw_hands();
	
	void reset_left_rotation();
	void reset_right_rotation();
	void left_rotation_update(struct gforce_t *gforce);
	void right_rotation_update(struct gforce_t *gforce);

	void draw_instructions();
	
public:
	ControlGame();

	int update(WPADData *wiimote_data, int state);
	void draw(int state);
	void text(int state);
};

#endif
